import java.util.Arrays;//util是工具的意思

public class test {
//    //拷贝
//    //1.通过for循环进行拷贝
//    public static void main(String[] args) {
//        int[] array = {1,2,3,4};
//        int[] copy = new int[array.length];
//        for (int i = 0; i < array.length; i++) {
//            copy[i] = array[i];
//        }
//        System.out.println(Arrays.toString(copy));
//    }

    //2.★★★★★★★使用Arrays.copyOf进行拷贝(你要拷贝的数组，新的长度）★★★★★★★
//    public static void main3(String[] args) {
//        int[] array = {1,2,3,4};
//        int[] copy = Arrays.copyOf(array,array.length);
//        System.out.println(Arrays.toString(copy));
//    }
//    public static void main(String[] args) {
//        int[] array = {1,2,3,4};
//        int[] copy = Arrays.copyOf(array,2*array.length);//扩容
//        System.out.println(Arrays.toString(copy));
//    }
    //3.System.arraycopy
//    public static void main(String[] args) {
//        int[] array = {1,2,3,4};
//        int[] copy = new int[array.length];
//        System.arraycopy(array,0,copy,0,array.length);
//        System.out.println(Arrays.toString(copy));
//    }
//    //4.通过数组名.clone() //array.clone()
//    public static void main(String[] args) {
//        int[] array = {1,2,3,4};
//        int[] copy = array.clone();
//        System.out.println(Arrays.toString(copy));
//        System.out.println(array);
//        System.out.println(copy);
//    }




/*

    public static String myTostring(int[] array){
        String str = "[";
        for (int i = 0; i < array.length; i++) {
            str = str + array[i];
            if(i != array.length-1){
                str+=",";
            }

        }
        str+="]";
        return str;
    }


    public static void main(String[] args) {
        int[] array = {1,2,3,4};
        String ret =myTostring(array);
        System.out.println(ret);
    }
*/

    /*public static String myTosring(int[] array){
        String str = "[";
        for (int i = 0; i < array.length; i++) {
                str = str +array[i];
                if(i != array.length-1){
                    str += ",";
                }
        }
        str += "]";
        return  str;
    }

    public static void main(String[] args) {
        int[] array = {1,2,3,4};
        String ret =myTosring(array);
        System.out.println(ret);
    }*/
   /* public static int[] func5() {
        int [] array = {1,2,3,4};//数组做返回值
        return array;
    }

    public static void main(String[] args) {
        int[] ret = func5();
        System.out.println(Arrays.toString(ret));
    }*/

  /*  public static void func(int n){
        n = 20;
    }

    public static void main(String[] args) {
        int a = 10;
        func(a);
        System.out.println(a);
    }*/


 /*   public static void main(String[] args) {
        int a = 10;//局部变量 存放到Java虚拟机栈里面
    }

    public static void main1(String[] args) {
        int[] array ={1,2,3};
        //第一种打印方式
        for (int i = 0; i < 3; i++) {
            System.out.print(array[i] + " ");
        }
        System.out.println();

        //第二种打印方式，for-each 增加for循环
        for ( int X: array) {
            System.out.print(X +" ");

        }
        System.out.println();
        //第三种方法 用arrays类  借助java本身提供的方法
        String ret = Arrays.toString(array); //把参数的数组转化为字符串进行观察
        System.out.println(ret);
    }*/
}
